package com.tsingteng.cosfun.ui.setting;

import com.tsingteng.cosfun.bean.UserBean;
import com.tsingteng.cosfun.callback.RxObserver;
import com.tsingteng.cosfun.mvp.presenter.BasePresenter;

/**
 * 描述 :
 * 创建人: 肖利.
 * 时间:2018/8/23
 * qq(872179966)
 */

public class MobileBindPresenter extends BasePresenter<MobileBindContract.IMobileBindView> implements MobileBindContract.IMobileBindPresenter {
    private MobileBindContract.IMobileBindView mView;
    private AccountMangeModel mModel;

    public MobileBindPresenter() {
        mModel = new AccountMangeModel();
    }

    @Override
    public void getMobileBind(String mobile, String verify_code, String bound_type) {
        mView = getView();
        RxObserver<Object> rxObserver = new RxObserver<Object>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                mView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(Object status) {
                mView.showMobileBindResult("");
            }
        };
        mModel.getMobileBind(mobile, verify_code, String.valueOf(System.currentTimeMillis()), bound_type, rxObserver);
        addDisposable(rxObserver);

    }

    @Override
    public void getVerifyCode(String mobile,String verify_type) {
        mView = getView();
        RxObserver<UserBean> rxObserver = new RxObserver<UserBean>(this) {
            @Override
            protected void onFaile(int errorCode, String errorMsg) {
                mView.showFail(errorMsg);
            }

            @Override
            protected void onSuccess(UserBean userBean) {
                mView.showVerifyCodeResult(userBean);
            }
        };

        mModel.verfyCode(mobile, verify_type, String.valueOf(System.currentTimeMillis()), rxObserver);
        addDisposable(rxObserver);
    }
}
